// ==UserScript==
// @include	   *.imvu.com/groups/*
// ==/UserScript==
window.addEventListener('DOMContentLoaded', function() {
	if ( widget.preferences.groupp == "enabled" ){
	var css = '#cusbutspacer,#cusbutspacer2,#cusbutspacer3,#cusbutspacer4{margin-right:70px!important}';
	var heads = document.getElementsByTagName("head");
	if (heads.length > 0) {
	var node = document.createElement("style");
	node.type = "text/css";
	node.appendChild(document.createTextNode(css));
	heads[0].appendChild(node);}
	var doc2 = document.location.href;
   	if(doc2.search("imvu.com/groups/group") > -1) {
	if(doc2.search("read.php?") > -1 || doc2.search("posting.php") > -1) {
	var imvubuttons = document.createElement("span");
	imvubuttons.setAttribute('id', 'custbuttons');
	var nl = document.createElement("input");
	nl.setAttribute('type', 'button');
	nl.setAttribute('style', 'width: 50px');
	nl.setAttribute('value', 'N URL');
	nl.setAttribute('name', 'cusbbnl');
	nl.setAttribute('class', 'PhorumSubmit');
	var nl2 = document.createElement("input");
	nl2.setAttribute('type', 'button');
	nl2.setAttribute('style', 'width: 60px');
	nl2.setAttribute('value', 'Img Link');
	nl2.setAttribute('name', 'cusbbn2');
	nl2.setAttribute('class', 'PhorumSubmit');
	nl2.setAttribute('id', 'cusbutspacer4');
	var nl3 = document.createElement("input");
	nl3.setAttribute('type', 'button');
	nl3.setAttribute('style', 'width: 32px');
	nl3.setAttribute('value', 'Img');
	nl3.setAttribute('name', 'cusbbn3');
	nl3.setAttribute('class', 'PhorumSubmit');
	var nl4 = document.createElement("input");
	nl4.setAttribute('type', 'button');
	nl4.setAttribute('style', 'width: 36px');
	nl4.setAttribute('value', 'URL');
	nl4.setAttribute('name', 'cusbbn4');
	nl4.setAttribute('class', 'PhorumSubmit');
	var nl5 = document.createElement("input");
	nl5.setAttribute('type', 'button');
	nl5.setAttribute('style', 'width: 20px');
	nl5.setAttribute('value', 'b');
	nl5.setAttribute('name', 'cusbbn5');
	nl5.setAttribute('class', 'PhorumSubmit');
	var nl6 = document.createElement("input");
	nl6.setAttribute('type', 'button');
	nl6.setAttribute('style', 'width: 20px');
	nl6.setAttribute('value', 'i');
	nl6.setAttribute('name', 'cusbbn6');
	nl6.setAttribute('class', 'PhorumSubmit');
	var nl7 = document.createElement("input");
	nl7.setAttribute('type', 'button');
	nl7.setAttribute('style', 'width: 20px');
	nl7.setAttribute('value', 'u');
	nl7.setAttribute('name', 'cusbbn7');
	nl7.setAttribute('class', 'PhorumSubmit');
	nl7.setAttribute('id', 'cusbutspacer');
	var nl8 = document.createElement("input");
	nl8.setAttribute('type', 'button');
	nl8.setAttribute('style', 'width: 50px');
	nl8.setAttribute('value', 'Strike');
	nl8.setAttribute('name', 'cusbbn8');
	nl8.setAttribute('class', 'PhorumSubmit');
	var nl9 = document.createElement("input");
	nl9.setAttribute('type', 'button');
	nl9.setAttribute('style', 'width: 50px');
	nl9.setAttribute('value', 'Center');
	nl9.setAttribute('name', 'cusbbn9');
	nl9.setAttribute('class', 'PhorumSubmit');
	nl9.setAttribute('id', 'cusbutspacer2');
	var nl10 = document.createElement("input");
	nl10.setAttribute('type', 'button');
	nl10.setAttribute('style', 'width: 35px');
	nl10.setAttribute('value', 'Sup');
	nl10.setAttribute('name', 'cusbbn10');
	nl10.setAttribute('class', 'PhorumSubmit');
	var nl11 = document.createElement("input");
	nl11.setAttribute('type', 'button');
	nl11.setAttribute('style', 'width: 35px');
	nl11.setAttribute('value', 'Sub');
	nl11.setAttribute('name', 'cusbbn11');
	nl11.setAttribute('class', 'PhorumSubmit');
	nl11.setAttribute('id', 'cusbutspacer3');
	var nl12 = document.createElement("input");
	nl12.setAttribute('type', 'button');
	nl12.setAttribute('style', 'width: 40px');
	nl12.setAttribute('value', 'Code');
	nl12.setAttribute('name', 'cusbbn12');
	nl12.setAttribute('class', 'PhorumSubmit');
	nl12.setAttribute('id', 'cusbutspacer5');
	var custbuttextarea = document.getElementById("phorum_textarea");
	custbuttextarea.parentNode.insertBefore(imvubuttons, custbuttextarea);
	document.getElementById("custbuttons").appendChild(nl5);
	document.getElementById("custbuttons").appendChild(nl6);
	document.getElementById("custbuttons").appendChild(nl7);
	document.getElementById("custbuttons").appendChild(nl8);
	document.getElementById("custbuttons").appendChild(nl9);
	document.getElementById("custbuttons").appendChild(nl10);
	document.getElementById("custbuttons").appendChild(nl11);
	document.getElementById("custbuttons").appendChild(nl12);
	document.getElementById("custbuttons").appendChild(nl3);
	document.getElementById("custbuttons").appendChild(nl2);
	document.getElementById("custbuttons").appendChild(nl4);
	document.getElementById("custbuttons").appendChild(nl);
	nl.addEventListener("click", myimfu_cusnamelink, false);
	nl2.addEventListener("click", myimfu_cusimglink, false);
	nl3.addEventListener("click", myimfu_cusimg, false);
	nl4.addEventListener("click", myimfu_cusurl, false);
	nl5.addEventListener("click", function(){myimfu_cusfontsty("b")}, false);
	nl6.addEventListener("click", function(){myimfu_cusfontsty("i")}, false);
	nl7.addEventListener("click", function(){myimfu_cusfontsty("u")}, false);
	nl8.addEventListener("click", function(){myimfu_cusfontsty("s")}, false);
	nl9.addEventListener("click", function(){myimfu_cusfontsty("center")}, false);
	nl10.addEventListener("click",function(){myimfu_cusfontsty("sup")}, false);
	nl11.addEventListener("click", function(){myimfu_cusfontsty("sub")}, false);
	nl12.addEventListener("click", function(){myimfu_cusfontsty("code")}, false);
	}}}
}, false);

function myimfu_cusfontsty(type){
var imvutxtarea = document.getElementById("phorum_textarea");
var styletxt = imvutxtarea.value.substring(imvutxtarea.selectionStart, imvutxtarea.selectionEnd);
var selLength = imvutxtarea.textLength;
var selStart = imvutxtarea.selectionStart;
var selEnd = imvutxtarea.selectionEnd; 
if (selEnd == 1 || selEnd == 2) selEnd = selLength; 
var s1 = (imvutxtarea.value).substring(0,selStart); 
var s2 = (imvutxtarea.value).substring(selStart, selEnd) 
var s3 = (imvutxtarea.value).substring(selEnd, selLength); 
imvutxtarea.value = s1 + "["+type+"]" + s2 + "[/"+type+"]" + s3; return;} 

function myimfu_cusnamelink(){
var lvalue = document.getElementsByName("body")[0]
var lurl = prompt("Enter Link", ""); 
if(lurl==null) { return; }
var lname = prompt("Enter Name", ""); 
if(lname==null) { return; }
else { lvalue.value = lvalue.value += "[url="+lurl+"]"+lname+"[/url]" } 
} 

function myimfu_cusimglink(){
var lvalue = document.getElementsByName("body")[0]
var liurl = prompt("Enter Link", ""); 
if(liurl==null) { return; }
var liname = prompt("Enter Image Link", ""); 
if(liname==null) { return; }
else { lvalue.value = lvalue.value += "[url="+liurl+"][img]"+liname+"[/img][/url]" } 
} 

function myimfu_cusimg(){
var lvalue = document.getElementsByName("body")[0]
var liurl = prompt("Enter Image Link", "");
if(liurl==null) { return; } 
else { lvalue.value = lvalue.value += "[img]"+liurl+"[/img]" } 
} 

function myimfu_cusurl(){
var lvalue = document.getElementsByName("body")[0]
var lurl = prompt("Enter Link", "");
if(lurl==null) { return; } 
else { lvalue.value = lvalue.value += "[url]"+lurl+"[/url]" } 
} 